// pages/practiceVacancy/index.js
const api = require('../../config/api')
const request = require('../../utils/request')
let app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    vacantSceneTaskList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {},
  // 获取当前孩子空缺训练列表
  async getVacantSceneList() {
    let patientid = wx.getStorageSync('patientInfo').id
    const res = await request.get(api.vacanciesTraining + patientid)
    if (res.httpStatus === 200) {
      res.data.forEach((item) => {
        item.startDate = item.startDate.split(' ')[0]
      })
      this.setData({
        vacantSceneTaskList: res.data,
      })
    }
  },
  // 点击跳转训练任务详情
  handleSceneTaskDetail(e) {
    let { trainingId, detailId, questionnaireId, trainingType } =
      e.currentTarget.dataset.item
    app.globalData.finishTaskEntrance = 2
    app.globalData.isVacancyIndex = 0
    if (Number(trainingType) === 1) {
      wx.navigateTo({
        url: '/pages/sceneTaskDetail/index?id=' + detailId,
      })
    } else {
      wx.redirectTo({
        url:
          '/pages/selfAssessment/question/index?key=1&id=' +
          questionnaireId +
          '&pathId=' +
          trainingId +
          '&taskFlowId=' +
          detailId,
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getVacantSceneList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
})
